package com.spancer.contentcenter;

import com.spancer.contentcenter.restinterceptor.RestTemplateTokenInterceptor;
import com.spancer.contentcenter.test.listener.SecondListener;
import com.spancer.contentcenter.test.registbean.Cow;
import com.spancer.contentcenter.test.registbean.MyCow;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.Collections;

@SpringBootApplication
@MapperScan(basePackages = "com.spancer")//扫描mybatis哪些包里面的接口
@EnableDiscoveryClient
@EnableFeignClients
//@Import(Cow.class )
public class ContentCenterApplication {

    public static void main(String[] args) {
        SpringApplication.run(ContentCenterApplication.class, args);

        //SpringApplication springApplication = new SpringApplication(ContentCenterApplication.class);
        //springApplication.addInitializers(new SecondInitializer());
        //springApplication.addListeners(new SecondListener());
        //springApplication.run(args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        RestTemplate template = new RestTemplate();
        // 设定resttemplate的自定义拦截器
        template.setInterceptors(Collections.singletonList(
                new RestTemplateTokenInterceptor() ));
        return template;
    }
}
